package com.etms.service;

import com.etms.mapper.IndexMapper;
import com.etms.pojo.IndexBox;
import com.etms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IndexService {
    @Autowired
    IndexMapper indexMapper;

    public Result getMsgById(Integer id) {
        IndexBox indexBox=indexMapper.findById(id);
        if(indexBox==null){
            return Result.failed("加载主页信息失败!");
        }
        return Result.successed(indexBox);
    }

    public Result updateIndex(IndexBox indexBox) {
        //处理格式
        String tag = indexBox.getTag();
        String msg = indexBox.getMsg();
        String notice = indexBox.getNotice();

        String tagHtml= "<br><span>"+tag.replaceAll("\n","<br>")+"</span>";
        String msgHtml="<span>"+msg.replaceAll("\n","<br>")+"</span><br>";
        String noticeHtml="<span>"+notice.replaceAll("\n","<br>")+"</span><br>";
        indexBox.setTag(tag).setMsg(msg).setNotice(notice).setNoticeHtml(noticeHtml).setMsgHtml(msgHtml).setTagHtml(tagHtml);
        int cnt=indexMapper.updateOne(indexBox);
        if(cnt==0){
            return Result.failed("修改失败!");
        }
        return Result.successed("更新成功!",null);
    }
}
